package com.hzh.jetpackcomposecompositionlocal.sample

import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.size
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.compositionLocalOf
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp

/**
 * @author huangzehui
 * @date 19/8/2025 上午12:05 周二
 * @description
 */

data class Elevations(
    val card: Dp = 0.dp
)


object CarElevation {
    val high: Elevations
        get() = Elevations(card = 10.dp)

    val low: Elevations
        get() = Elevations(card = 5.dp)
}

/**
 * 创建CompositionLocal
 */
val LocalElevations = compositionLocalOf {
    // LocalElevations.current 就是这个对象
    Elevations()
}

@Composable
fun MyCard(
    elevation: Dp = LocalElevations.current.card,
    backgroundColor: Color,
    content: @Composable ColumnScope.() -> Unit,
) {
    Card(
        onClick = { },
        elevation = CardDefaults.cardElevation(
            defaultElevation = elevation
        ),
        modifier = Modifier.size(200.dp),
        colors = CardDefaults.cardColors().copy(containerColor = backgroundColor),
        content = content
    )
}